//
//  BaseTabBarController.m
//  lvfj
//
//  Created by lvfeijun on 2022/8/24.
//  Copyright © 2022 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//

#import "BaseTabBarController.h"

@interface BaseTabBarController ()

@end

@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.tabBar addObserver:self forKeyPath:@"hidden" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self.tabBar removeObserver:self forKeyPath:@"hidden"];
}

///监听打印tabar隐藏时的堆栈信息
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"hidden"]) {
        NSInteger new = [change[@"new"] integerValue];
        if (!new) {
            NSInteger old = [change[@"old"] integerValue];
            UINavigationController *navctl = nil;
            if ([self.selectedViewController isKindOfClass:UINavigationController.class]) {
                navctl = self.selectedViewController;
            } else if ([self.selectedViewController isKindOfClass:UIViewController.class]){
                navctl = self.selectedViewController.navigationController;
            }
            NSArray *ctls= [navctl isKindOfClass:UINavigationController.class]?navctl.viewControllers:@[];
            DDLogInfo(@"tabBarShow: new:%ld,old:%ld,viewControllers:%@",new,old,ctls);
            //方法2:方法调用的堆栈信息,打印堆栈信息
            NSArray *csss = [NSThread callStackSymbols];
            DDLogInfo(@"=====>>>>>堆栈<<<<<=====\n%@",csss);
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
